#include "hdrImageReader.h"

/*hdrImageReader::hdrImageReader(void)
{
	reader = NULL;
	io = NULL;
	bridge = NULL;
	lastData = NULL;
}

hdrImageReader::~hdrImageReader(void)
{
	if(reader)
		reader->Delete();
	if(io)
		io->Delete();
	if(lastData)
		lastData->Delete();
}*/

//void hdrImageReader::Open(char* filename)
void hdrImageReader::loadDataSetFromFile(std::string file, vtkDataSet **data)
{
        ReaderType::Pointer reader = ReaderType::New();

        itk::AnalyzeImageIO::Pointer io = itk::AnalyzeImageIO::New();
	
        ImageToVTKType::Pointer bridge = ImageToVTKType::New();
	
	reader->SetImageIO(io);

        reader->SetFileName(file);

        reader->Update();

        bridge->SetInput(reader->GetOutput());

        bridge->UpdateOutputInformation();

        bridge->Update();

        //*data = bridge->GetOutput();

        vtkImageData *imdata = bridge->GetOutput();
        vtkImageCast *imgCast = vtkImageCast::New();
        imgCast->SetInput(imdata);
        imgCast->SetOutputScalarTypeToUnsignedShort();
        imgCast->Update();

        *data = imgCast->GetOutput();
        //*/
        //vtkDataSet *output = (vtkDataSet *) bridge->GetOutput();
        //vtkDataSet *lastData = (vtkDataSet*)vtkDataSet::New();
        //lastData->DeepCopy(output);

        //bridge->Delete();

        //io->Delete();

        //reader->Delete();

        //return set;// output; //lastData;

}

/*void hdrImageReader::Update(void)
{
	reader->Update();

	bridge->SetInput(reader->GetOutput());

	bridge->UpdateOutputInformation();

	bridge->Update();

	lastData = (vtkDataSet *) bridge->GetOutput();
}

vtkDataSet *hdrImageReader::GetOutput(void)
{
	return lastData;
}

void hdrImageReader::Close(void)
{
	if(reader)
		reader->Delete();
	if(io)
		io->Delete();
	if(bridge)
		bridge->Delete();
	//if(lastData)
	//	lastData->Delete();
}
*/
